package com.estate.parking.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.estate.bean.Complaint;
import com.estate.bean.Parking;
import com.estate.parking.service.ParkingService;
import com.estate.util.JsonResult;
import com.estate.util.ResultTool;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/parking")
@Slf4j

public class ParkingController {

    @Resource
    private ParkingService parkingService;

    @GetMapping("list/{page}/{size}")
    public JsonResult list(@PathVariable("page") int page, @PathVariable("size") int size) {
        log.info("page:{},size:{}", page, size);
        JsonResult result = parkingService.listByPage(page, size);
        log.info("result:{}", result);
        return result;
    }

    @PostMapping("/save")
    public JsonResult save(Parking parking) {
        log.info("新增parking:{}", parking);
        JsonResult result = parkingService.savePacking(parking);
        log.info("result:{}", result);
        return result;
    }

    @PutMapping("/update")
    public JsonResult update(Parking parking) {
        log.info("修改parking:{}", parking);
        JsonResult result = parkingService.updateParking(parking);
        log.info("result:{}", result);
        return result;
    }

    @DeleteMapping("/delete")
    public JsonResult delete(@RequestParam("parkingId") String parkingId) {
        log.info("删除parking:{}", parkingId);
        JsonResult result = parkingService.deleteParking(parkingId);
        log.info("result:{}", result);
        return result;
    }

    @GetMapping("/list/{parkingId}")
    public JsonResult list(@PathVariable("parkingId") String parkingId) {
        log.info("parkingId:{}", parkingId);
        JsonResult result = ResultTool.success(parkingService.getById(parkingId));
        log.info("result:{}", result);
        return result;
    }

    @GetMapping("/findByCommunityId/{communityId}")
    public Long findByCommunityId(@PathVariable("communityId") String communityId) {
        log.info("communityId:{}", communityId);
        QueryWrapper<Parking> wrapper = new QueryWrapper();
        wrapper.eq("community_id", communityId);
        long count = parkingService.count(wrapper);
        log.info("result:{}", count);
        return count;
    }
}
